package 软件秘笈_设计模式;


public class 工厂方法模式 {
    public static void main(String[] args) {
        ISwordFactory swordFactory = new Caocao();
        AbstractSword sword = swordFactory.createSword();
        System.out.println(sword.getName());
    }
}

/**
 * 抽象的剑
 */
abstract class AbstractSword{
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
class QixingSword extends AbstractSword{
    public QixingSword(){
        this.setName("七星宝刀");
    }
}
class BaXingSword extends AbstractSword{
    public BaXingSword(){
        this.setName("八星宝刀");
    }
}

/**
 * 宝刀工厂
 */
interface ISwordFactory{
    public AbstractSword createSword();
}

/**
 * 曹操具体工厂
 */
class Caocao implements ISwordFactory{
    @Override
    public AbstractSword createSword() {
        return new QixingSword();
    }
}
/**
 * 曹操2具体工厂
 */
class Caocao2 implements ISwordFactory{

    @Override
    public AbstractSword createSword() {
        return new QixingSword();
    }
}